import {parseToChart2,restPostApi} from '../apis/core-util';

export default class ResponseDistributionScope {
  constructor(container) {
    this.container = container;

    this.$state = {
      reponseDistributionData:{
        loading:true
      }
    };

    this.responseDistributionApi = restPostApi({
      __url: 'http/stat/'+ BlueWare.appId + '/range',
      __type: 'laterBlock',
      viewKey:'response_distribution',
      appVersionId: ()=>BlueWare.appVersionId,
      dateType: ()=>this.container.dateType
    });
  }

  $load() {
    this.responseDistributionApi.fetch().done((data, params)=>{
      this.$state.reponseDistributionData = {
        data: parseToChart2(data, params)
      };

      this.container.emit();
    }).fail((error,params)=>{
      this.$state.reponseDistributionData = {error};
      this.container.emit();
    }).progress(()=>{
      this.$state.reponseDistributionData = {loading: true};

      this.container.emit();
    });
  }
}
